package com.ruoyi.web.controller.builderTest;

public class Product {
    private String partA;
    private String partB;
    private String partC;

    public void setPartA(String partA) {
        this.partA = partA;
    }

    public void setPartB(String partB) {
        this.partB = partB;
    }

    public void setPartC(String partC) {
        this.partC = partC;
    }
    public void show(){
        System.out.println("显示产品的组成部分");
    }
    // 建造者接口
    public interface Builder {
        void buildPartA();
        void buildPartB();
        void buildPartC();
        Product getResult();
    }
    public static class ConcreteBuilder implements Builder {
         Product product = new Product();
        @Override
        public void buildPartA() {
            System.out.println("组成部分A");
        }

        @Override
        public void buildPartB() {
            System.out.println("组成部分B");
        }

        @Override
        public void buildPartC() {
            System.out.println("组成部分C");
        }

        @Override
        public Product getResult() {
            return product;
        }
    }
    //指挥类
    public static class Director{
        private Builder builder;
        public Director(Builder builder){
            this.builder = builder;
        }
        public Product construct(){
            builder.buildPartA();
            builder.buildPartB();
            builder.buildPartC();
            return builder.getResult();
        }
    }
    public static void main(String[] args) {
        Builder builder = new ConcreteBuilder();
        Director director = new Director(builder);
        Product product = director.construct();
        product.show();
    }

}
